//
//  LuckyLotteryViewController.m
//  Cai8
//
//  Created by zhoubo on 2017/6/19.
//  Copyright © 2017年 zhoubo. All rights reserved.
//

#import "LuckyLotteryViewController.h"
#import "LotteryModel11.h"


@interface LuckyLotteryViewController ()

@property (nonatomic,strong) UIImageView* imgview;

@property (nonatomic,strong) UILabel* lotteryLabel;

@property (nonatomic,strong) UILabel* luckyLabel;

@property (nonatomic,strong) NSArray* models;

@end

@implementation LuckyLotteryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    int x = arc4random_uniform(self.models.count);
    
    LotteryModel11* model = self.models[x];
    self.imgview.image = [UIImage imageNamed:model.imgname];
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.title = NSLocalizedString(@"幸运彩票", @"幸运彩票");
    
    
    self.imgview.frame = CGRectMake(ScreenWidth()/2 - 50, 150, 100, 100);


//    [self viewAnimation:self.imgview];
    

    CGFloat imgHeight = CGRectGetMaxY(self.imgview.frame);
    CGFloat margin = 20;
    

    self.lotteryLabel.text = [NSString stringWithFormat:@"%@: %@",self.title,model.name];
    self.lotteryLabel.frame = CGRectMake(0, imgHeight+margin, ScreenWidth(), 30);
    
//    [self.lotteryLabel sizeToFit];
    
    self.lotteryLabel.textAlignment = NSTextAlignmentCenter;
    
    
    self.luckyLabel.frame = CGRectMake(0, CGRectGetMaxY(self.lotteryLabel.frame)+margin, ScreenWidth(), 30);
    self.luckyLabel.text = [NSString stringWithFormat:@"%@: %@",NSLocalizedString(@"幸运指数", @"幸运指数"),model.apple];;
//    [self.luckyLabel sizeToFit];
    self.luckyLabel.textAlignment = NSTextAlignmentCenter;

    

    
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = false;

}

-(void)viewWillDisappear:(BOOL)animated
{
////    self.tabBarController.tabBar.hidden = false;
//    [UIView animateWithDuration:0.3 animations:^{
//        self.tabBarController.tabBar.alpha = 1;
//    }];

    
}


-(void)viewAnimation:(UIView*)view
{
    
    [UIView animateWithDuration:2 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:0.5 options:UIViewAnimationOptionLayoutSubviews animations:^{
        view.frame = CGRectMake(ScreenWidth()/2 - 50, 150, 100, 100);
    } completion:nil];
    /* 旋转 */
    
    // 对Y轴进行旋转（指定Z轴的话，就和UIView的动画一样绕中心旋转）
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    
    // 设定动画选项
    animation.duration = 5; // 持续时间
    animation.repeatCount = 100; // 重复次数
    
    // 设定旋转角度
    animation.fromValue = [NSNumber numberWithFloat:0.0]; // 起始角度
    animation.toValue = [NSNumber numberWithFloat:2 * M_PI]; // 终止角度
    
    // 添加动画
    [view.layer addAnimation:animation forKey:@"rotate-layer"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

-(UIImageView *)imgview
{
    if (_imgview == nil) {
        _imgview = [[UIImageView alloc]init];
        _imgview.frame = CGRectMake(0, (ScreenHeight()-300)/2, 300, 300);
        [self.view addSubview:_imgview];
        _imgview.backgroundColor = [UIColor redColor];
    }
    return _imgview;
}


-(UILabel *)lotteryLabel
{
    if (_lotteryLabel == nil) {
        _lotteryLabel = [[UILabel alloc]init];
        _lotteryLabel.textColor = [UIColor grayColor];
        _lotteryLabel.font = [UIFont systemFontOfSize:18];

        [self.view addSubview:_lotteryLabel];
    }
    return _lotteryLabel;
}

-(UILabel *)luckyLabel
{
    if (_luckyLabel == nil) {
        _luckyLabel = [[UILabel alloc]init];
        _luckyLabel.textColor = [UIColor grayColor];
        _luckyLabel.font = [UIFont systemFontOfSize:18];
        [self.view addSubview:_luckyLabel];
    }
    return _luckyLabel;
}

-(NSArray *)models
{
    if (_models == nil) {
        _models = [LotteryModel11 getModels];
    }
    return _models;
}

@end
